﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
using MyClassLibrary;
using MyDB;

namespace MyProgram
{
    public partial class FrmDivAdd : FrmBaseModify
    {
        public FrmDivAdd()
        {
            InitializeComponent();
            //this.label2.Visible = false;
            //this.label3.Visible = false;
            this.label3.Text = Divname;
        }
       
        internal string Divname;

        MedicareDataClassesDataContext db = new MedicareDataClassesDataContext();

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Divisions div = new Divisions { 科別名 = this.textBox1.Text };
        
            if (this.label3.Text=="")
            {
                db.Divisions.InsertOnSubmit(div);
            }
            else
            {
                var q = (from f in db.Divisions
                         where f.科別名 == this.label3.Text
                         select f).First();
                q.科別名 = this.textBox1.Text;
            }

            db.SubmitChanges();

            ClsRecord.Record(sender, this.Name);

            this.Close();
        }

        private void FrmDivAdd_Load(object sender, EventArgs e)
        {
            this.label3.Text = Divname;
        }
    }
}
